package com.woniuxy.kaer.shop.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.kaer.commons.jwtUtil.JwtUtil;
import com.woniuxy.kaer.commons.util.Result;
import com.woniuxy.kaer.form.EvaluateOrderForm;
import com.woniuxy.kaer.form.EvaluateReplyForm;
import com.woniuxy.kaer.param.EvaluateOrderParam;
import com.woniuxy.kaer.param.EvaluateReplyParam;
import com.woniuxy.kaer.shop.service.ProductEvaluateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  商品评价
 * </p>
 *
 * @author 郭建东
 * @since 2025年02月17日
 */
@RestController
@RequestMapping("/productEvaluate")
@Api(tags = "商品评价管理")
public class ProductEvaluateController {

    @Resource
    private ProductEvaluateService productEvaluateService;

    @Resource
    private JwtUtil jwtUtil;

    @PostMapping("/evaluate")
    @ApiOperation("评价商品订单")
    public Result evaluate(@RequestBody EvaluateOrderForm form,@RequestHeader("token") String token)throws Exception{
        Integer userId = jwtUtil.getUserId(token);
        productEvaluateService.evaluate(BeanUtil.toBean(form, EvaluateOrderParam.class),userId);
        return Result.succeed("评价成功",null);
    }

    @PostMapping("/evaluateReply")
    @ApiOperation("回复评价")
    public Result evaluateReply(@RequestBody EvaluateReplyForm form, @RequestHeader("token") String token)throws Exception{
        Integer managerId = jwtUtil.getManagerId1(token);
        productEvaluateService.evaluateReply(BeanUtil.toBean(form, EvaluateReplyParam.class),managerId);
        return Result.succeed("回复成功",null);
    }

}

